<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>公司部门职位</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-store, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta http-equiv="expires" content="-1">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="/dist/img/icon.png" type="image/x-icon">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="/dist/plugins/bootstrap/css/bootstrap.min.css">
    <!--字体-->
    <!--图标-->
    <link rel="stylesheet" href="/dist/css/ionicons.min.css">
    <!--插件样式-->
    <link href="/dist/plugins/ztree/css/zTreeStyle/zTreeStyle.css" rel="stylesheet"/>
    <link rel="stylesheet" href="/dist/plugins/fixedTable/fixed-table.css" />
    <!--OA主样式-->
    <link rel="stylesheet" href="/dist/css/OA.min.css?t=39cd89cd">
    <link rel="stylesheet" href="/dist/css/skins/OA-skins.min.css?t=16f1e6f3">
    <style type="text/css">
        #divRoleName {
            position: fixed;
            bottom: 9px;
            top: 0px;
            width: 180px;
            border-right: 1px solid #a5bacf;
            background-color: white;
            opacity: 1;
            top: 10px;
            text-align: center;
            overflow: auto;
            display: none;
        }

        .roleNumberModel {
            display: none;
        }
        .left{
            float: left;
            width:220px;
        }
        .right{
            margin-left: 230px;
        }
        .fixed-table_body tr td{
            border-right: none;
            font-size: 12px;
            text-align: center;
        }
        .fixed-table_header tr th{
            border-right: none;
            background: yellow;
            font-weight: normal;
            font-size: 12px;
            text-align: center;
        }
        .fixed-table_body tr:nth-of-type(odd){
            background: #F9F9F9;
        }
    </style>
</head>
<body>
<section class="content" id="app">
    <div class="row">
        <div class="left">
            <div class="box-body no-padding box-border iframeH" style="overflow: auto;background: #f7f8fa;">
                <ul class="ztree" id="ulGroupCompanyDepartRole"></ul>
                <div id="menu" style="width: 120px;">
                    <div id="addCompany">
                        添加公司
                    </div>
                    <div id="addDepart">
                        添加部门
                    </div>
                    <div id="addRole">
                        添加岗位
                    </div>
                </div>
                <div id="menu2" style="width: 120px;">
                    <div id="roleNumber">
                        配置岗位目标人数
                    </div>
                </div>
            </div>
        </div>
        <div class="right">
            <div class="box-body no-padding box-border" style="overflow: auto;background: #fff;">
                <div class="box-header with-border" style="background: #f7f8fa;">
                    <div class="pull-right">
                        <div class="has-feedback">

                            <input id="key" type="text" placeholder="姓名/电话" class="form-control input-sm">
                            <span id="btnQuery" class="glyphicon glyphicon-search form-control-feedback"></span>
                        </div>
                    </div>
                    <input type="button" value="添加人员" id="addUserBtn" class="btn oaBtn btn-sm pull-right"
                           @click="addUser" style="margin-right:10px;" v-if="isShowBtn('addUser')"/>
                    <div class="oa-pager pull-right" style="margin-right: 10px;">
                        <span id="nowPage">1</span>/<span id="allPage">1</span>&nbsp;&nbsp;&nbsp;
                        <span class="oa-pager-button" id="prev">上一页</span>
                        <span class="oa-pager-button" id="next">下一页</span>
                    </div>
                </div>
                <div class="box-body no-padding iframeH2" style="overflow: auto;">
                    <div class="fixed-table-box head-fixed ">
                        <!-- 表头 start -->
                        <div class="fixed-table_header-wraper">
                            <table class="fixed-table_header" cellspacing="0" cellpadding="0" border="0">
                                <thead>
                                <tr>
                                    <th style="width: 119px;"><div class="table-cells">姓名</div></th>
                                    <th style="width: 119px;"><div class="table-cells">电话</div></th>
                                    <th style="width: 119px;"><div class="table-cells">公司</div></th>
                                    <th style="width: 119px;"><div class="table-cells">部门</div></th>
                                    <th style="width: 119px;"><div class="table-cells">职位</div></th>
                                    <th style="width: 119px;"><div class="table-cells">上级</div></th>
                                    <th style="width: 119px;"><div class="table-cells">是否在职</div></th>
                                    <th class="text-center" style="width: 120px;">
                                        <div class="table-cells">操作</div>
                                    </th>
                                    <th style="width: 18px;"><div class="table-cells"></div></th>
                                </tr>
                                </thead>
                            </table>
                        </div>
                        <!--内容-->
                        <div class="fixed-table_body-wraper iframeH2Fixed">
                            <table class="fixed-table_body table-hover" cellspacing="0" cellpadding="0" border="0" style="width: 100%;">
                                <tbody id="tbList">
                                <tr v-for="user in list_users">
                                    <td>{{user.name}}</td>
                                    <td>{{user.tel}}</td>
                                    <td>{{user.companyName}}</td>
                                    <td>{{user.departName}}</td>
                                    <td>{{user.roleName}}</td>
                                    <td>{{user.parentName}}</td>
                                    <td>
                                        <div v-if="user.jobState===1">否</div>
                                        <div v-else="">是</div>
                                    </td>
                                    <td class="text-center">
                                        <a href="javascript:void(0);" @click="gotoDetail(user)">查看</a>
                                        <a href="javascript:void(0);" v-if="isShowBtn('addUser')"
                                           @click="modifyUser(user.id)">修改</a>
                                        <a href="javascript:void(0);" v-if="isShowBtn('resetPwd')"
                                           @click="resetPwdUser(user)">重置密码</a>
                                        <a href="javascript:void(0);" v-if="isShowBtn('configUserRight')"
                                           @click="configUserRight(user.name,user.id,user.roleId)">配置权限</a>
                                        <a href="javascript:void(0);" v-if="isShowBtn('configUserRegion')"
                                           @click="configUserRegion(user.name,user.id,user.roleId)">配置区域</a>
                                        <a href="javascript:void(0);" v-if="isShowBtn('leaveUser')"
                                           @click="setJobState(user.id)">离职</a>
                                        <a href="javascript:void(0);" v-if="isShowBtn('addUser')"
                                           @click="reEntry(user)">重新入职</a>

                                    </td>
                                </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <!--<table class="table table-hover table-striped">-->
                        <!--<thead>-->
                        <!--<tr>-->
                            <!--<th>姓名</th>-->
                            <!--<th>电话</th>-->
                            <!--<th>公司</th>-->
                            <!--<th>部门</th>-->
                            <!--<th>职位</th>-->
                            <!--<th>上级</th>-->
                            <!--<th>是否在职</th>-->
                            <!--<th class="text-center">操作</th>-->
                        <!--</tr>-->
                        <!--</thead>-->
                        <!--<tbody id="tbList">-->
                        <!--<tr v-for="user in list_users">-->
                            <!--<td style="width:100px;">{{user.name}}</td>-->
                            <!--<td style="width:100px;">{{user.tel}}</td>-->
                            <!--<td style="width:100px;">{{user.companyName}}</td>-->
                            <!--<td style="width:100px;">{{user.departName}}</td>-->
                            <!--<td style="width:120px;">{{user.roleName}}</td>-->
                            <!--<td style="width:100px;">{{user.parentName}}</td>-->
                            <!--<td style="width:100px;">-->
                                <!--<div v-if="user.jobState===1">否</div>-->
                                <!--<div v-else="">是</div>-->
                            <!--</td>-->
                            <!--<td class="text-center">-->
                                <!--<a href="javascript:void(0);" @click="gotoDetail(user)">查看</a>-->
                                <!--<a href="javascript:void(0);" v-if="isShowBtn('addUser')"-->
                                   <!--@click="modifyUser(user.id)">修改</a>-->
                                <!--<a href="javascript:void(0);" v-if="isShowBtn('resetPwd')"-->
                                   <!--@click="resetPwdUser(user)">重置密码</a>-->
                                <!--<a href="javascript:void(0);" v-if="isShowBtn('configUserRight')"-->
                                   <!--@click="configUserRight(user.name,user.id,user.roleId)">配置权限</a>-->
                                <!--<a href="javascript:void(0);" v-if="isShowBtn('configUserRegion')"-->
                                   <!--@click="configUserRegion(user.name,user.id,user.roleId)">配置区域</a>-->
                                <!--<a href="javascript:void(0);" v-if="isShowBtn('leaveUser')"-->
                                   <!--@click="setJobState(user.id)">离职</a>-->
                                <!--<a href="javascript:void(0);" v-if="isShowBtn('addUser')"-->
                                   <!--@click="reEntry(user)">重新入职</a>-->

                            <!--</td>-->
                        <!--</tr>-->
                        <!--</tbody>-->
                    <!--</table>-->
                    <div id="divRoleName">
                        <div style="height:28px;text-align: center;line-height:30px;padding-top:2px;">
                            <input type="button" value="确定" class="btn btn-primary btn-xs" id="btnConfirm"
                                   @click="addRoles"/>
                            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                            <input type="button" value="关闭" class="btn btn-default btn-xs" id="btnClose"
                                   @click="closeRoles"/>
                            <input type="text" placeholder="输入姓名查询..." class="form-control input-sm search-text"
                                   style="width: 80%;float:left;">
                            <input type="button" class="btn btn-default btn-xs search-button"
                                   style="width: 20%;float:left;height: 25px;" value="搜索">
                        </div>
                        <div style="width:100%;height:78%;overflow:auto;">
                            <ul class="ztree" id="ulRoleName"></ul>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
    <div class="roleNumberModel">
        <input type="text" placeholder="请设定目标人数" class="form-control pull-left" style="width: 200px; margin-left: 10px;"
               id="roleNumberNumber">
        <input type="button" value="保存" class="btn oaBtn  pull-left" style="margin-left: 10px;" id="roleNumberSave">
    </div>
</section>
<!--<div id="menu" style="width: 120px;">-->
<!--<div id="recover">-->
<!--恢复-->
<!--</div>-->
<!--</div>-->
<!--JQ-->
<script src="https://file.ggxqce.com/web/jquery-2.2.3.min.js"></script>
<!--插件JS-->
<script src="https://file.ggxqce.com/web/bootstrap.min.js"></script>
<!--框架已定义 JS-->
<script src="/dist/js/app_iframe.js?t=602456c3"></script>
<!--oa自定义  JS-->
<script src="/dist/js/oa.js?t=42e28def"></script>

<script src="https://file.ggxqce.com/web/vue.min.js"></script>
<!--ztree组件所需js-->
<script type="text/javascript" src="/dist/plugins/ztree/js/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="/dist/plugins/ztree/js/jquery.ztree.exhide-3.5.js"></script>
<script type="text/javascript" src="/dist/plugins/easyui/plugins/jquery.menu.js"></script>
<script type="text/javascript" src="/dist/plugins/easyui/plugins/jquery.parser.js"></script>
<script type="text/javascript" src="/dist/plugins/lhgdialog/lhgdialog.min.js?self=true"></script>
<script src="/dist/plugins/fixedTable/fixed-table.js"></script>

<script type="text/javascript">
    //左侧区域z-tree的回调方法
    var zTreeCallback = {
        showIcon: function (treeeId, treeNode) {
            return treeNode.isParent;
        },
        onClick: function (event, treeId, treeNode) {
            $.wyui.page.queryParams.requestPage = 1;
            $.wyui.page.queryParams.companyId = '';
            $.wyui.page.queryParams.departId = '';
            $.wyui.page.queryParams.roleId = '';
            $.wyui.page.queryParams.key = '';
            switch (treeNode.type) {
                case 'company':
                    $.wyui.page.queryParams.companyId = treeNode.dataId;
                    break;
                case 'depart':
                    $.wyui.page.queryParams.departId = treeNode.dataId;
                    break;
                case 'role':
                    $.wyui.page.queryParams.roleId = treeNode.dataId;
                    break;
                default :
                    break;
            }
            $.wyui.page.getByPage();
        },
        showRemoveBtn: function (treeId, treeNode) {
            if (treeNode.type == "role") {
                return true;
            }
            if (treeNode.type == "company") {
                if (app.isShowBtn('addCompany')) {
                    return true;
                }
            }
            if (treeNode.type == "depart") {
                if (app.isShowBtn('addDepart')) {
                    return true;
                }
            }
            if (treeNode.type == "role") {
                if (app.isShowBtn('addRole')) {
                    return true;
                }
            }
        },
        showRenameBtn: function (treeId, treeNode) {
            if (treeNode.type == "role") {
                return false;
            }
            if (treeNode.type == "company") {
                if (app.isShowBtn('addCompany')) {
                    return true;
                }
            }
            if (treeNode.type == "depart") {
                if (app.isShowBtn('addDepart')) {
                    return true;
                }
            }
            if (treeNode.type == "role") {
                if (app.isShowBtn('addRole')) {
                    return true;
                }
            }
        },
        beforeDrag: function (treeId, treeNodes) {
            if (getCurrentUser().id != "201711271733404C9DA1461F2421F828"&&getCurrentUser().id != "2017121616084F0B9E200AC4144BD435"&&getCurrentUser().id != "20181225104845A39592A1B15EA0E4F3"&&getCurrentUser().id !="2018122514044056AEEB36BBC4A93BF6") {
                console.log("您没有拖动权限");
                return false;
            }
            var thisType = treeNodes[0].type;
            if (thisType == "root") {
                return false;
            }
            for (var i = 0, l = treeNodes.length; i < l; i++) {
                if (treeNodes[i].drag === false) {
                    return false;
                }
            }
            return true;
        },
        beforeDrop: function (treeId, treeNodes, targetNode, moveType) {
            var thisType = treeNodes[0].type;
            var toType = targetNode.type;
            console.log(toType);
            if (targetNode.getParentNode()) {
                var toPrentType = targetNode.getParentNode().type;
            }
            if (treeNodes[0].type == "company") {
                if (toType == "depart" && moveType == "inner" || toPrentType == "depart" || toType == "role" && toPrentType == "depart") {
                    return false;
                }
            }
            if (treeNodes[0].type == "depart") {
                if (toType == "root" || toType == "role" && moveType == "inner" || toPrentType == "role" || toType == "role" && toPrentType == "role") {
                    return false;
                }
            }
            if (treeNodes[0].type == "role") {
                if (toType == "root" || toType == "role" && moveType == "inner" || toPrentType == "role" || toType == "role" && toPrentType == "role") {
                    return false;
                }
            }
            var r = confirm("您确定要修改该 部门/职位 的所在位置吗？")
            if (r == true) {
                return targetNode ? targetNode.drop !== false : true;
            }
            else {
                return false;
            }

        },
        onDrop: function (event, treeId, treeNodes, targetNode, moveType, isCopy) {
            var node = treeNodes[0].getParentNode();
            console.log(treeNodes[0]);
            console.log(node);
//            $.wyui.postMethod(urlConfig.system.region.save, {id:treeNodes[0].id,companyId:node.id}, function (data) {
//                console.log("修改大区成功");
//                console.log(data)
//            });

            var thisType = treeNodes[0].type;
            console.log(thisType)
            //换级
            if (thisType == "company") {//公司只能放到组织结构 或者公司下级
                var changeData = '';
                if (node.type == "company" || node.parentId != "0") {
                    changeData = {id: treeNodes[0].id, parentId: node.id}
                } else {
                    changeData = {id: treeNodes[0].id, parentId: "0"}
                }
                $.wyui.postMethod(urlConfig.system.company.save, changeData, function (data) {
                    console.log("修改公司成功");
                    console.log(data)
                });
            }
            if (thisType == "depart") {
                var changeData = '';
                if (node.type == "company" && node.parentId != "0") {
                    changeData = {id: treeNodes[0].id, parentId: "0", companyId: node.id}
                }//移动到公司
                else if (node.type == "company" && node.parentId == "0") {
                    changeData = {id: treeNodes[0].id, companyId: node.id, parentId: "0"}
                }//移动到集团
                else {
                    changeData = {id: treeNodes[0].id, companyId: node.companyId, parentId: node.id}
                }
                $.wyui.postMethod(urlConfig.system.depart.save, changeData, function (data) {
                    console.log("修改部门成功");
                    console.log(data)
                });
            }
            if (thisType == "role") {
                $.wyui.postMethod(urlConfig.system.role.save, {
                    id: treeNodes[0].id,
                    departId: node.id
                }, function (data) {
                    console.log("修改岗位成功");
                    console.log(data)
                });
            }
            //排序：
            var url = thisType == "company" ? urlConfig.system.company.sort : thisType == "depart" ? urlConfig.system.depart.sort : urlConfig.system.role.sort;

            var newNodes = new Array()
            for (var i = 0; i < node.children.length; i++) {
                var data = node.children[i]
                newNodes.push(data.dataId)
            }
            var ids = newNodes.join(",");
            var obj = thisType == "company" ? {companyIds: ids} : thisType == "depart" ? {departIds: ids} : {roleIds: ids};
            $.wyui.postMethod(url, obj, function (data) {
            });
        },
        beforeEditName: function (treeId, treeNode) {

            app.treeObj.editName(treeNode);
            return false;
        },
        beforeRemove: function (treeId, treeNode) {
            if (confirm("确认删除吗？")) {
                treeNode.delFlag = 1;
                var url = "";
                switch (treeNode.type) {
                    case "company":
                        url = urlConfig.system.company.delById;
                        break;
                    case "depart":
                        url = urlConfig.system.depart.delById;
                        break;
                    case "role":
                        url = urlConfig.system.role.delById;
                    default:
                        break;
                }
                $.wyui.postMethod(url, {id: treeNode.dataId}, function (data) {
                    app.treeObj.removeNode(treeNode);
                });
            }
            return false;
        },
        beforeRename: function (treeId, treeNode, newName, isCancel) {
            if (newName.length == 0) {
                setTimeout(function () {
                    app.treeObj.cancelEditName();
                    alert("不能为空");
                }, 0);
            } else {
                var url = "";
                switch (treeNode.type) {
                    case "company":
                        url = urlConfig.system.company.save;
                        break;
                    case "depart":
                        url = urlConfig.system.depart.save;
                        break;
                    case "role":
                        url = urlConfig.system.role.save;
                    default:
                        break;
                }
                $.wyui.postMethod(url, {
                    id: treeNode.dataId,
                    name: newName,
                    updateUserId: getCurrentUser().id
                }, function () {
                    treeNode.name = newName;
                    app.treeObj.cancelEditName(newName);
                    app.treeObj.cancelSelectedNode(treeNode);
                });
            }
            return false;
        },
        addHoverDom: function (treeId, treeNode) {
            switch (treeNode.type) {
                case "root":
                    if (!app.isShowBtn('addCompany')) {
                        return;
                    }
                    break;
                case "company":
                    if (!app.isShowBtn('addCompany') && !app.isShowBtn('addDepart')) {
                        return;
                    }
                    break;
                case "depart":
                    if (!app.isShowBtn('addDepart') && !app.isShowBtn('addRole')) {
                        return;
                    }
                    break;
                default:
                    return;
                    break;
            }
            var sObj = $("#" + treeNode.tId + "_span");
            if (treeNode.editNameFlag || $("#addBtn_" + treeNode.tId).length > 0) return;
            var addStr = "<span class='button add' id='addBtn_" + treeNode.tId
                + "' title='添加' onfocus='this.blur();'></span>";
            sObj.after(addStr);
            var btn = $("#addBtn_" + treeNode.tId);
            if (btn) btn.bind("click", function () {
                if (!treeNode || treeNode.type == 'role') return;
                app.treeObj.selectNode(treeNode);
                // alert(treeNode.type)
                $("#menu").children().hide();
                $("#menu div").removeClass("menu-show")
                switch (treeNode.type) {
                    case "root":
                        if (app.isShowBtn('addCompany')) {
                            $.wyui.postMethod(urlConfig.system.company.save, {
                                name: '新建公司',
                                sortNo: treeNode.children ? treeNode.children.length : 0,
                                delFlag: 0,
                                address: '',
                                createUserId: getCurrentUser().id,
                                parentId: treeNode.dataId,
                                updateUserId: getCurrentUser().id
                            }, function (data) {
                                var newNode = app.treeObj.addNodes(treeNode, {
                                    id: "company_" + data.id,
                                    pId: treeNode.id,
                                    name: "新建公司",
                                    type: "company",
                                    dataId: data.id,
                                    companyId: data.id,
                                    isParent: true
                                }, true)[0];
                                app.treeObj.editName(newNode);
                            });
                            return;
                        } else {
                            $("#addCompany").hide();
                            $("#addCompany").removeClass("menu-show")
                        }
                        break;
                    case "company":
                        if (app.isShowBtn('addCompany')) {
                            $("#addCompany").show();
                            $("#addCompany").addClass("menu-show")
                        } else {
                            $("#addCompany").hide();
                            $("#addCompany").removeClass("menu-show")
                        }
                        if (app.isShowBtn('addDepart')) {
                            $("#addDepart").show();
                            $("#addDepart").addClass("menu-show")
                        } else {
                            $("#addDepart").hide();
                            $("#addDepart").removeClass("menu-show")
                        }

                        if ($("#menu .menu-show").length == 0) {
                            return;
                        }
                        break;
                    case "depart":
                        if (app.isShowBtn('addDepart')) {
                            $("#addDepart").show();
                            $("#addDepart").addClass("menu-show")
                        } else {
                            $("#addDepart").hide();
                            $("#addDepart").removeClass("menu-show")
                        }

                        if (app.isShowBtn('addRole')) {
                            $("#addRole").show();
                            $("#addRole").addClass("menu-show")
                        } else {
                            $("#addRole").hide();
                            $("#addRole").removeClass("menu-show")
                        }

                        if ($("#menu .menu-show").length == 0) {
                            return;
                        }
                        break;

                    default:
                        break;
                }

                $('#menu').menu('show', {
                    left: event.clientX,
                    top: event.clientY
                });
                return false;
            });
        }, removeHoverDom: function (treeId, treeNode) {
            $("#addBtn_" + treeNode.tId).unbind().remove();
        },
        onRightClick: function (event, treeId, treeNode) {
//            if (treeNode.type == "role") {
//                app.treeObj.selectNode(treeNode);
//                $('#menu2').menu('show', {
//                    left: event.clientX,
//                    top: event.clientY
//                });
//            }

        }
    };
    //左侧区域z-tree的基本设置
    var zTreeSetting = {
        view: {
            showIcon: zTreeCallback.showIcon,
            addHoverDom: zTreeCallback.addHoverDom,
            removeHoverDom: zTreeCallback.removeHoverDom
        },
        data: {
            simpleData: {
                enable: true
            },
            keep: {
                parent: true
            }
        },
        edit: {
            drag: {
                autoExpandTrigger: true
            },
            enable: true,
            editNameSelectAll: true,
            removeTitle: '删除',
            renameTitle: '修改',
            showRemoveBtn: zTreeCallback.showRemoveBtn,
            showRenameBtn: zTreeCallback.showRenameBtn
        },
        callback: {
            onClick: zTreeCallback.onClick,
            beforeDrag: zTreeCallback.beforeDrag,
            beforeDrop: zTreeCallback.beforeDrop,
            onDrop: zTreeCallback.onDrop,
            beforeEditName: zTreeCallback.beforeEditName,
            beforeRemove: zTreeCallback.beforeRemove,
            beforeRename: zTreeCallback.beforeRename,
            onRightClick: zTreeCallback.onRightClick
        }
    };
    //左侧添加职位z-tree的基本设置
    var zTreeRoleName_setting = {
        view: {
            showIcon: function (treeId, treeNode) {
                return treeNode.isParent;
            }
        },
        data: {
            simpleData: {
                enable: true
            }
        },
        check: {
            enable: true
        }
    };
</script>
<script type="text/javascript">
    //配置页面列表查询所需的基本参数
    $.wyui.page.dataUrl = server.ip + urlConfig.system.system.getUserViewBySqlWhere;
    /*$.wyui.page.queryParams.companyId = getCurrentUser().companyId;*/
    $.wyui.page.queryParams.userId = getCurrentUser().id;
    $.wyui.page.queryParams.departId = '';
    $.wyui.page.queryParams.roleId = '';
    $.wyui.page.queryParams.key = '';
    $.wyui.page.getByPage_callback = function (list) {
        app.list_users = list;
    };
</script>
<script type="text/javascript">
    var app = new Vue({
        title: '编辑人员',
        el: "#app",
        data: {
            treeObj: null,//页面左侧部门列表
            treeRoleName: null,//配置职位的ztree
            list_users: [],//右侧列表数据
            rightOp: []//权限列表
        },
        methods: {
            reEntry: function (user) {
                var that = this;
                if (user.jobState == 1) {
                    $.wyui.postMethod('/user/reEntry.json',
                        {
                            userId: user.id,
                            jobState: -1
                        },
                        function (r) {
                            console.log(r);
                            if (r.result == true) {
                                alert("入职成功");
                                that.modifyUser(user.id);
                            } else {
                                alert("入职失败");
                            }
                        });
                }
            },
            isHasRightOp: function (eName) {
                return $.inArray(eName, this.rightOp) > -1;
            },
            isShowBtn: function (eName) {
                if (getCurrentUser().superUser || this.isHasRightOp(eName)) {
                    return true;
                } else {
                    return false;
                }
            },
            addUser: function () {
                top.$.dialog({
                    content: 'url:/page/personnel/entry.html?pageType=edit' + "&t=" + new Date(),
                    title: '办理入职',
                    width: 904,
                    height: 613,
                    max: true,
                    min: true,
                    lock: true
                }).max();
            },
            modifyUser: function (userId) {
                top.$.dialog({
                    content: 'url:/page/personnel/entry.html?id=' + userId + '&pageType=edit&t=' + new Date(),
                    title: '修改人员',
                    width: 904,
                    height: 613,
                    max: true,
                    min: true,
                    lock: true
                }).max();
            },
            gotoDetail: function (item) {
                top.$.dialog({
                    content: 'url:/page/personnel/entry.html?id=' + item.id + '&pageType=look',
                    title: item.name + "详情",
                    width: 904,
                    height: 613,
                    max: true,
                    min: true,
                    lock: true
                }).max();
            },
            resetPwdUser: function (user) {
                var r = confirm("您确定要重置 " + user.name + " 的账号密码吗？")
                if (r == true) {
                    var data = {
                        pwd: "111111",
                        id: user.id,
                        updateUserId: getCurrentUser().id
                    };
                    $.wyui.postMethod( "/user/resetPwd.json", data, function (r) {
                        alert("密码已重置成功")
                    });
                }
            },
            checkUser: function (userId) {
                top.addTabs({
                    id: "look" + userId,
                    title: "人员详情",
                    close: true,
                    url: '/personnel/entry.html?id=' + userId + '&pageType=look'
                });

            },
            setJobState: function (userId) {
                top.$.dialog({
                    content: 'url:/page/personnel/quit.html?id=' + userId + '&t=' + new Date(),
                    title: '办理离职',
                    width: 662,
                    height: 280,
                    max: false,
                    min: false,
                    lock: true
                });
            },
            configRoleRight: function (node) {
                top.$.dialog({
                    content: 'url:/page/admin/role_right.html?roleId=' + node.dataId,
                    title: "职位权限配置",
                    modal: false,
                    width: 500,
                    height: 350,
                    max: true,
                    min: false
                });
            },
            configUserRight: function (userName, userId, roleId) {
                top.$.dialog({
                    content: 'url:/page/admin/user_right.html?userId=' + userId + "&t=" + new Date(),
                    title: userName + "-权限配置",
                    modal: false,
                    width: 800,
                    height: 400,
                    max: true,
                    min: false
                });
            },
            configUserRegion: function (userName, userId, roleId) {
                top.$.dialog({
                    content: 'url:/page/admin/user_region.html?userId=' + userId + "&t=" + new Date(),
                    title: userName + "-区域配置",
                    modal: false,
                    width: 800,
                    height: 400,
                    max: true,
                    min: false
                });
            },
            addRoles: function () {
                var departNode = app.treeObj.getSelectedNodes()[0];
                if (!departNode) {
                    alert("请选择部门");
                    return;
                }
                var roleNodes = app.treeRoleName.getCheckedNodes(true);
                if (roleNodes.length == 0) {
                    alert("请选择职位");
                    return;
                }
                for (var i = 0; i < roleNodes.length; i++) {
                    if (roleNodes[i].id != "0") {
                        $.wyui.postMethod(urlConfig.system.role.save, {
                            id: "",
                            name: "",
                            departId: departNode.dataId,
                            sortNo: departNode.children ? departNode.children.length : 0,
                            delFlag: 0,
                            roleNameId: roleNodes[i].id
                        }, function (data) {
                            app.treeObj.addNodes(departNode, {
                                id: "role_" + data.id,
                                name: roleNodes[i].name,
                                departId: departNode.dataId,
                                sortNo: departNode.children ? departNode.children.length : 0,
                                delFlag: 0,
                                roleNameId: roleNodes[i].id,
                                type: 'role',
                                dataId: data.id
                            });
                        }, true);
                    }
                }
                app.treeObj.expandNode(departNode, true, false, false, false);
                app.treeRoleName.checkAllNodes(false);
                $("#divRoleName").hide();
            },
            closeRoles: function () {
                $("#divRoleName").hide();
            }
            //配置岗位人数

        },
        mounted: function () {
            var that = this;
            //获取左侧区域-z-tree
            $.wyui.postMethod(urlConfig.system.system.getOrgTreeNodesByUserId, {userId: getCurrentUser().id}, function (nodes) {
                //循环 将区域中岗位的 目标人数 显示到树种
                for (var i = 0; i < nodes.length; i++) {
                    if (nodes[i].targetNumber != "0") {
                        if (nodes[i].type == "role") {
                            nodes[i].name = nodes[i].name + " (" + nodes[i].targetNumber + "人)";
                        }
                    }
                }
                that.treeObj = $.fn.zTree.init($("#ulGroupCompanyDepartRole"), zTreeSetting, nodes);
            });
            //获取左侧添加岗位时需要显示的z-tree
            $.wyui.postMethod(urlConfig.system.roleName.getTreeNodes, {}, function (nodes) {
                that.treeRoleName = $.fn.zTree.init($("#ulRoleName"), zTreeRoleName_setting, nodes);
                //不显示离职人员
                that.treeRoleName.hideNodes(that.treeRoleName.getNodesByParam("delFlag", 1));
            });
            //查询用户有哪些权限
            $.wyui.postMethod(urlConfig.system.rightOp.getRightOpByUserId, {userId: getCurrentUser().id}, function (rightOp) {
                for (var i = 0; i < rightOp.length; i++) {
                    that.rightOp.push(rightOp[i].eName);
                }

                console.log("权限列表如下：")
                console.log(that.rightOp);
                //判断用户是否有添加人员的权限
//                if (!getCurrentUser().superUser && !that.isHasRightOp('addUser')) {
//                    $("#addUserBtn").hide();
//                } else {
//                    $("#addUserBtn").show();
//                }
            });

        }
    });
    $('#btnQuery').on('click', function () {
        var key = $("#key").val();
        $.wyui.page.queryParams.key = $.trim(key);
        $.wyui.page.queryParams.requestPage = 1;
        /*$.wyui.page.queryParams.companyId = getCurrentUser().superUser ? "" : getCurrentUser().companyId;*/
        $.wyui.page.queryParams.userId = getCurrentUser().id;
        $.wyui.page.queryParams.departId = '';
        $.wyui.page.queryParams.roleId = '';
        $.wyui.page.getByPage();
    });
    $("input[type='text']").keypress(function (e) {
        if (event.keyCode == 13) {
            event.cancelBubble = true;
            event.returnValue = false;
            $(this).parents("div").find("#btnQuery").click();
        }
    });

    //页面刷新
    function refresh() {
        $.wyui.page.getByPage();
    }
</script>
<script type="text/javascript">
    // 操作右键菜单
    $(function () {
        //添加公司、部门、职位
        $("#menu").menu({
            hideOnUnhover: false,
            onClick: function (item) {
                var node = app.treeObj.getSelectedNodes()[0];
                switch (item.id) {
                    case "addCompany":
                        $.wyui.postMethod(urlConfig.system.company.save, {
                            name: '新建公司',
                            sortNo: node.children ? node.children.length : 0,
                            delFlag: 0,
                            address: '',
                            createUserId: getCurrentUser().id,
                            parentId: node.dataId,
                            updateUserId: getCurrentUser().id
                        }, function (data) {
                            var newNode = app.treeObj.addNodes(node, {
                                id: "company_" + data.id,
                                pId: node.id,
                                name: "新建公司",
                                type: "company",
                                dataId: data.id,
                                companyId: data.id,
                                isParent: true
                            }, true)[0];
                            app.treeObj.editName(newNode);
                        });
                        break;
                    case "addDepart":
                        var parentId = "0";
                        if (node.type == 'depart') {
                            parentId = node.dataId;
                        }
                        $.wyui.postMethod(urlConfig.system.depart.save, {
                            name: '新建部门',
                            sortNo: node.children ? node.children.length : 0,
                            delFlag: 0,
                            companyId: node.companyId,
                            createUserId: getCurrentUser().id,
                            updateUserId: getCurrentUser().id,
                            level: node.level,
                            parentId: parentId,
                            type: '0'
                        }, function (data) {
                            var newNode = app.treeObj.addNodes(node, {
                                id: "depart_" + data.id,
                                pId: node.id,
                                name: "新建部门",
                                type: "depart",
                                dataId: data.id,
                                isParent: true,
                                companyId: node.companyId
                            }, true)[0];
                            app.treeObj.editName(newNode);
                        });
                        break;
                    case "addRole":
                        $("#divRoleName").show();
                        break;

                    default:
                        break;
                }
            }
        });
        //配置岗位目标人数
        $("#menu2").menu({
            hideOnUnhover: false,
            onClick: function (item) {
                var node = app.treeObj.getSelectedNodes()[0];
                $("#roleNumberSave").attr("roleId", node.id);
                $.dialog({
                    content: $('.roleNumberModel').html(),
                    title: "配置岗位（" + node.roleName + "）目标人数",
                    modal: true,
                    width: 400,
                    height: 100,
                    max: false,
                    min: false
                });
            }
        });
        //配置岗位人数
        //配置岗位人数
        $("body").delegate("#roleNumberSave", "click", function () {
            var id = $("#roleNumberSave").attr("roleId");
            var number = $("#roleNumberNumber").val();
            $.wyui.postMethod(urlConfig.system.role.saveTargetNumber, {id: id, targetNumber: number}, function (r) {
                var node = app.treeObj.getNodeByParam("id", id, null);
                if (node.targetNum == "0") {
                    node.name = node.name + " (" + number + "人)";
                } else {
                    node.name = (node.name).split("(")[0] + " (" + number + "人)";
                }
                app.treeObj.updateNode(node);
                alert("配置成功");
                $(".ui_close").click();
            });
        })
        $("input.search-text").keypress(function (e) {
            if (event.keyCode == 13) {
                searchTree()
            }
        });
        $(".search-button").on('click', function () {
            searchTree()
        });

        function searchTree() {
            var text = $(".search-text").val();
            var treeObj = $.fn.zTree.getZTreeObj("ulRoleName");
            console.log()
            if (text != "") {
                nodeList = treeObj.getNodesByParamFuzzy("name", text);
                treeObj.cancelSelectedNode();
                for (var n in nodeList) {
                    treeObj.selectNode(nodeList[n], true);
                    findParent(treeObj, nodeList[n]);
                }
            } else {
                treeObj.cancelSelectedNode();
            }
        }

        function findParent(treeObj, node) {
            treeObj.expandNode(node, true, false, false);
            var pNode = node.getParentNode();
            if (pNode != null) {
                nodeList.push(pNode);
                findParent(treeObj, pNode);
            }
        }
    });
</script>
<script>
    //初始化FixedTable
    $(".fixed-table-box").fixedTable();
</script>
</body>
</html>
